/**
 * 区块链网络配置
 * 定义支持的区块链网络及其RPC URL等信息
 */

const networks = {
  ethereum: {
    name: "以太坊",
    chainId: "0x1", // 主网
    testChainId: "0xaa36a7", // Sepolia测试网
    rpcUrl:
      process.env.ETHEREUM_RPC_URL || "https://sepolia.infura.io/v3/your_key",
    symbol: "ETH",
    blockExplorer: "https://sepolia.etherscan.io",
    isTestnet: true,
  },
  bsc: {
    name: "币安智能链",
    chainId: "0x38", // 主网
    testChainId: "0x61", // 测试网
    rpcUrl:
      process.env.BSC_RPC_URL ||
      "https://data-seed-prebsc-1-s1.binance.org:8545",
    symbol: "BNB",
    blockExplorer: "https://testnet.bscscan.com",
    isTestnet: true,
  },
  polygon: {
    name: "Polygon",
    chainId: "0x89", // 主网
    testChainId: "0x13881", // Mumbai测试网
    rpcUrl: process.env.POLYGON_RPC_URL || "https://rpc-mumbai.maticvigil.com",
    symbol: "MATIC",
    blockExplorer: "https://mumbai.polygonscan.com",
    isTestnet: true,
  },
  arbitrum: {
    name: "Arbitrum",
    chainId: "0xa4b1", // 主网
    testChainId: "0x66eed", // Sepolia测试网
    rpcUrl:
      process.env.ARBITRUM_RPC_URL || "https://sepolia-rollup.arbitrum.io/rpc",
    symbol: "ETH",
    blockExplorer: "https://sepolia.arbiscan.io",
    isTestnet: true,
  },
};

/**
 * 获取指定网络的配置
 * @param {string} networkId 网络ID
 * @returns {Object} 网络配置
 */
function getNetwork(networkId) {
  return networks[networkId] || networks.ethereum; // 默认返回以太坊网络
}

/**
 * 获取所有支持的网络列表
 * @returns {Array} 网络列表
 */
function getNetworkList() {
  return Object.keys(networks).map((key) => ({
    id: key,
    ...networks[key],
  }));
}

module.exports = {
  networks,
  getNetwork,
  getNetworkList,
};
